package com.scau.clothes.stock.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.scau.clothes.core.util.CheckObjectIsNullUtils;
import com.scau.clothes.stock.mapper.CategoryMapper;
import com.scau.clothes.stock.model.entity.Category;
import com.scau.clothes.stock.service.CategoryService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category>implements CategoryService {
    @Resource
    private CategoryMapper categoryMapper;

    private CheckObjectIsNullUtils checkObjectIsNullUtils = new CheckObjectIsNullUtils();
    @Override
    public int insertCategory(Category category) {
        category.setIsDelete(0);
        return categoryMapper.insert(category);
    }

    @Override
    public int updateCategory(Category category) {
        return categoryMapper.updateById(category);
    }

    @Override
    public int deleteCategory(Category category) {
        category.setIsDelete(1);
        return categoryMapper.updateById(category);
    }

    @Override
    public List<Category> listCategory(Category category) {
        QueryWrapper<Category> queryWrapper=new QueryWrapper<>();
        queryWrapper.ne("is_delete", 1);
        if(!checkObjectIsNullUtils.objCheckIsNull(category)){
            if (category.getCategoryId() != null)
                queryWrapper.eq("category_id",category.getCategoryId());
            if (StrUtil.isNotBlank(category.getCategoryName()))
                queryWrapper.like("category_name",category.getCategoryName());
        }
        List<Category> list=list(queryWrapper);
        return list;
    }
}
